package com.bizzard.system.controller;

import com.bizzard.basic.util.AjaxResult;
import com.bizzard.basic.util.PageList;
import com.bizzard.system.domain.Systemdictionarydetail;
import com.bizzard.system.query.SystemdictionarydetailQuery;
import com.bizzard.system.service.ISystemdictionarydetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接口类
 */

@RestController
@RequestMapping("/systemdictionarydetail")
@Api(value = "保障接口",description = "保障接口")
public class SystemdictionarydetailController {
    @Autowired
    private ISystemdictionarydetailService iSystemdictionarydetailService;

    /**
     *  查询单个对象接口
     * @param id
     * @return
     */
    @ApiOperation(value = "查询单个对象")
    @GetMapping("/{id}")
    public Systemdictionarydetail findOne (@PathVariable("id")Long id){
        return  iSystemdictionarydetailService.findById(id);

    }

    /**
     *  查询所有对象接口
     * @return
     */
    @ApiOperation(value = "查询所有对象")
    @GetMapping
    public List<Systemdictionarydetail> findAll (){
        return  iSystemdictionarydetailService.findAll();

    }

    /**
     *  分页查询接口
     * @param systemdictionarydetailQuery
     * @return
     */
    @ApiOperation(value = "分页查询")
    @PostMapping
    public PageList<Systemdictionarydetail> queryPage (@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery){
        return  iSystemdictionarydetailService.queryPage(systemdictionarydetailQuery);

    }

    /**
     *  删除操作接口
     * @param id
     * @return
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    public AjaxResult delete (@PathVariable("id") Long id){
        try {
            iSystemdictionarydetailService.del(id);
            return  new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }

    }




    /**
     *  添加和修改 接口
     */
    @PutMapping
    @ApiOperation(value = "添加或修改")
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarydetail systemdictionarydetail){
        try {
            if(systemdictionarydetail.getId() == null){//添加
                iSystemdictionarydetailService.add(systemdictionarydetail);
            }else{
                iSystemdictionarydetailService.update(systemdictionarydetail);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PatchMapping
    @ApiOperation(value = "批量删除接口")
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        try {
            iSystemdictionarydetailService.patchDelete(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"批量删除失败");
        }
    }


}
